package user

import (
	"context"
	"fmt"

	"github.com/google/uuid"
)

// validateConversationAccess 验证用户是否有权限访问指定会话
func (h *UserHandler) validateConversationAccess(userID uuid.UUID, conversationIDStr string) error {
	conversationID, err := uuid.Parse(conversationIDStr)
	if err != nil {
		return fmt.Errorf("invalid conversation ID format")
	}

	ctx := context.Background()
	hasAccess, err := h.repos.GetConversation().CheckConversationAccess(
		ctx,
		conversationID,
		userID,
	)
	if err != nil {
		return fmt.Errorf("database error: %w", err)
	}
	if !hasAccess {
		return fmt.Errorf("conversation not found or access denied")
	}

	return nil
}
